import VueRouter from "vue-router";
import login from "@/pages/login";
import index from "@/pages/index"
import Home from "@/pages/Home";
import jobs from "@/pages/jobs";
import jobDetails from "@/pages/jobDetails";
import message from "@/pages/message";
import Chart from "@/pages/Chart";
import delivery from "@/pages/Mine/delivery";
import index2 from "@/pages/enterprise/index"
import publish from "@/pages/enterprise/publish";
import apply from "@/pages/enterprise/apply";
import test from "@/pages/test";
import Mine from "@/pages/Mine/Mine";
import Feedback from "@/pages/Mine/Feedback";
import interview from "@/pages/enterprise/interview";
import interview2 from "@/pages/Mine/interview"
const router= new VueRouter({
    routes: [
        {
          path:'/',
          redirect:'/index'
        },
        {
            path: '/login',
            component: login
        },
        {
            path: '/index',
            component: index,
            beforeEnter:(to,from,next)=>{
                if(localStorage.getItem("type")=='1'){
                    next()
                }
                else router.push("/index2")
            },
            children: [
                {
                    path: "",
                    redirect: 'home'
                },
                {
                    path: 'home',
                    name: 'home',
                    component: Home
                },
                {
                    path: 'jobs',
                    component: jobs
                },
                {
                    path: 'jobdetails',
                    component: jobDetails
                },
                {
                    path: 'message',
                    component: message
                },
                {
                    path:'chart',
                    component: Chart
                },
                {
                    path:'delivery',
                    component:delivery
                },
                //我的
                {
                    path: 'mine',
                    component: Mine,
                    children:[{
                        path:'delivery',
                        component:delivery
                        },
                        {
                            path:'chart',
                            component:message
                        },
                        {
                            path:'feedback',
                            component:Feedback
                        },
                        {
                            path:'interview',
                            component:interview2
                        }]
                }
            ]
        },
        //企业端
        {
            path:'/index2',
            component: index2,
            children:[
                {
                    path: 'publish',
                    component: publish
                },
                {
                    path: 'message',
                    component: message
                },
                {
                    path: 'apply',
                    component: apply
                },
                {
                    path: 'interview',
                    component: interview
                }
            ]
        },
        {
            path: '/test',
            component: test
        }
    ]
})
router.beforeEach((to, from, next)=>{
        if(to.fullPath==='/login'||localStorage.getItem("token")){
            next()
        }
        else router.push('/login')
})
export default router